import { Controller, UseGuards, Get, Post, Delete, Param, ParseIntPipe, Patch, Body } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { AuthGuard } from '@src/guard/auth.guard';
import adminConfig from '@src/config/admin.config';
import { AccountService } from '@src/services/admin/system/account/account.service';
import { CurrentUser } from '@src/decorators/current.user';
import { CreateAccountDto } from './dto/create.account.dto';
import { AccountEntity } from '@src/entities/model/admin/system/account.entity';
import { UpdateAccountDto } from './dto/update.account.dto';

@ApiTags('账号管理') // 文档上用的
@ApiBearerAuth() // 文档上的
@UseGuards(AuthGuard) // 接口请求 
@Controller(`${adminConfig.adminPath}/account`) //基础路径
export class AccountController {
  constructor (
    private readonly accountService: AccountService,
  ) { }

  @ApiOperation({
    summary: '创造账号',
    description: '新增账号',
  })
  @Post()
  async createAccount(
    @Body() createAccountDto: CreateAccountDto,
  ): Promise<AccountEntity> {
    return await this.accountService.createAccount(createAccountDto);
  }

  @ApiOperation({
    summary: '删除账号',
    description: '根据id删除账号',
  })
  @Delete(':id')
  async deleteAccountById(
    @Param('id', new ParseIntPipe()) id: number,
  ): Promise<string> {
    return await this.accountService.deleteAccountById(id);
  }

  @ApiOperation({
    summary: '修改数据',
    description: '根据id修改账号',
  })
  @Patch(':id')
  async modifyAccountById(
    @Param('id', new ParseIntPipe()) id: number,
    @Body() updateAccountDto: UpdateAccountDto,
  ): Promise<string> {
    return await this.accountService.modifyAccountById(id, updateAccountDto);
  }

  @ApiOperation({
    summary: '获取账号列表',
    description: '根据条件获取账号列表',
  })
  @Get()
  async accountList(): Promise<any> {
    return await this.accountService.accountList();
  }
}
